//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hktk_app/pages/mine/calendar.dart';
import 'package:hktk_app/pages/select/select_exam_page.dart';
import 'package:hktk_app/painter/triangle_painter.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';

/// 首页标题
class HomeTitleWidget extends StatelessWidget {
  /// 倒计时
  final int countdown;

  /// 类目名称
  final String categoryName;

  const HomeTitleWidget(
      {super.key, required this.countdown, required this.categoryName});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 40,
      margin: EdgeInsets.only(left: 16, right: 16),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _dropDown(context),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              GestureDetector(
                onTap: () {
                  Navigator.pushNamed(context, "/mine/calendar");
                },
                child: SvgPicture.asset("images/home/calendar.svg",
                    width: 20, height: 20),
              ),
              Text.rich(TextSpan(children: [
                TextSpan(
                    text: countdown < 0 ? "0" : countdown.toString(),
                    style:
                        FontUtil.fontBlack1(22, fontWeight: FontWeight.w500)),
                TextSpan(text: "天", style: FontUtil.fontBlack1(16)),
                TextSpan(text: " 考试倒计时", style: FontUtil.fontGrey1(17))
              ])),
            ],
          )
        ],
      ),
    );
  }

  /// 下拉组件实现
  Widget _dropDown(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pushNamed(context, "/select-exam");
      },
      child: Container(
          // decoration: BoxDecoration(color: Colors.blue),
          // padding: EdgeInsets.symmetric(horizontal: 5),
          child: Row(
            children: [
              Text(
                categoryName,
                style: FontUtil.fontBlack1(16, fontWeight: FontWeight.w500),
              ),
              hiSpace(width: 8),
              SizedBox(
                width: 8,
                height: 8,
                child: CustomPaint(
                  painter: TrianglePainter(),
                ),
              )
            ],
          )),
    );
  }
}
